<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>隔行变色</title>
	<script type="text/javascript">
        window.onload = function(){
        	//document.getElementsByTagName  通过标签获取元素  返回一个集合 
        	//document.getElementsById       通过id获取元素    返回一个对象
        	var aLi = document.getElementsByTagName('li');
        	for(var i=0;i<aLi.length;i++){
        		if(i%2==0){
        			aLi[i].style.background = '#ccc';
        		}else{
        			aLi[i].style.background = '';
        		}
        	}
        }


	</script>
</head>
<body>


    <ul>
    	<li></li>
    	<li></li>
    	<li></li>
    	<li></li>
    	<li></li>
    	<li></li>
    	<li></li>
    	<li></li>
    	<li></li>
    	<li></li>
    </ul>
	
</body>
</html>